package com.neu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.VipmanageMapper;

import com.neu.po.VipmanageExample.Criteria;
import com.neu.po.Vipmanage;
import com.neu.po.VipmanageExample;

@Service
public class VipManageServiceImpl implements VipManageService{
	@Autowired
	private VipmanageMapper vipmanageMapper;
	
	@Override
	public int insert(Vipmanage vipmanage) {
		
		return vipmanageMapper.insert(vipmanage);
	}

	@Override
	public int update(Vipmanage vipmanage) {
		
		return vipmanageMapper.updateByPrimaryKey(vipmanage);
		
	}

	@Override
	public int delete(int id) {
		
		return vipmanageMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Vipmanage> getAllVIP() {
		VipmanageExample example = new VipmanageExample();
		
		return vipmanageMapper.selectByExample(example);
	}

	@Override
	public PageInfo<Vipmanage> getPaged(int pageNum, int pageSize, String keyword) {
		VipmanageExample example = new VipmanageExample();
		Criteria c = example.createCriteria();
		
		c.andDelmarkEqualTo(1).andVipcodeLike("%"+keyword+"%");
			
		PageHelper.startPage(pageNum, pageSize);
		
		List<Vipmanage> list = vipmanageMapper.selectByExample(example);
		
		PageInfo<Vipmanage> pageInfo = new PageInfo<>(list);
		
		return pageInfo;
	}

	@Override
	public int batchDeleteVIP(List<Integer> ids) {
		VipmanageExample example = new VipmanageExample();
		example.or().andIdIn(ids);		
		
		return vipmanageMapper.deleteByExample(example);
	}

	@Override
	public List<Vipmanage> getVIPById(int id) {
		VipmanageExample example = new VipmanageExample();
		example.or().andIdEqualTo(id);
		return vipmanageMapper.selectByExample(example);
	}

	
	
}
